package com.ityibai.bootstrap.controller;

import com.ityibai.bootstrap.entity.User;
import com.ityibai.bootstrap.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * Created by YinLin on 18/5/22.
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "user/save")
    public User save() {
        User user = new User();
        user.setName(UUID.randomUUID().toString().replace("-", "").substring(0, 5));
        user.setAge(new Random().nextInt(100));
        userService.save(user);
        return user;
    }

    @RequestMapping(value = "users")
    public List<User> users() {
        return userService.findAll();
    }
}
